package cmd

import (
	"fmt"
	"github.com/spf13/cobra"
	"os"
)

var (
	rootCmd = &cobra.Command{
		Use:   "ConcurrentRunner",
		Short: "Concurrent Runner",
		Long:  "并发执行命令",
	}
	maxProcess       int
	concurrentNumber int
	command          string
	batchCommandFile string
)

func Execute() {
	if err := rootCmd.Execute(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}

func init() {
	rootCmd.PersistentFlags().IntVarP(&maxProcess, "max", "m", 10, "最大同时执行数量")
	rootCmd.PersistentFlags().IntVarP(&concurrentNumber, "number", "n", 1, "配置并发数量")
	rootCmd.PersistentFlags().StringVarP(&command, "command", "c", "", "并发命令")
	rootCmd.PersistentFlags().StringVarP(&batchCommandFile, "file",
		"f", "",
		"命令文件 使用文件，如果使用此命令，则数量和命令无效。\n文件格式为:\n并发数量 命令\n并发数量 命令\n")
}
